#include "RdfProjectControl.h"
#include "model/rdf/Cls.h"
#include "model/rdf/KnowledgeBase.h"
#include "model/rdf/Slot.h"
#include "model/rdf/Instance.h"
#include "model/rdf/Factory.h"
#include "dal/RdfFactory.h"

namespace xpm {
	RdfProjectControl::RdfProjectControl() {

	}

	Project* RdfProjectControl::createNewRdfProject() {
		RdfFactory* factory = new RdfFactory();
		Project* project = new Project(factory);

		string baseName = "carlo";
		// arbitrary string
		string myNamespace = "http://www.cis.umac.mo/\~jzguo/pages/research/";
		//string myNamespace = "http://test/";

		project->setProjectFilePath("e:\\test\\" + baseName + ".pprj");
		factory->setSourceFiles(project->getSources(), baseName + ".rdfs",
			                    baseName + ".rdf", myNamespace);

		return project;
	}

	void RdfProjectControl::populateProject(Project* project) {
		KnowledgeBase* kb = project->knowledgeBase();
		// create a subclass of :THING
		Cls* clsA = kb->createCls("Foo", kb->getRootClses());
		// create a subclass of clsA
		Cls* clsASub = kb->createCls("FooSub", clsA);

		// add a multivalued slot to clsA
		Slot* multiSlot = kb->createSlot("multiSlot");
		multiSlot->setValueType(STRING);
		multiSlot->setAllowsmultipleValues(true);
		clsA->addDirectTempleteSlot(multiSlot);

		// add a singlevalued slot to clsA
		Slot* singleSlot = kb->createSlot("singleSlot");
		singleSlot->setValueType(STRING);
		singleSlot->setAllowsmultipleValues(false);
		clsA->addDirectTempleteSlot(singleSlot);

		// create instance of clsASub
		Instance* instance = kb->createInstance("xxx", clsASub);

		// set a multi-valued slot vlaue
		vector<string> values;
		values.push_back("value1");
		values.push_back("value2");
		instance->setOwnSlotValues(multiSlot, values);

		// set a single-values slot value
		instance->setOwnSlotValue(singleSlot, "value3");
	}

	void RdfProjectControl::saveProject(Project* p) {
		p->save();
	}
}